package com.jimmy.medical.service;

import com.jimmy.medical.base.JpaSpecificationService;
import com.jimmy.medical.entity.*;
import com.jimmy.medical.model.OrderReport;
import com.jimmy.medical.model.SignInfo;
import com.jimmy.medical.model.UserTask;
import com.jimmy.medical.repository.FlowOrderRepository;
import com.jimmy.medical.model.FeeInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

import java.util.List;


/**
 * 工单Service
 *
 * @author jimmy
 */
public interface IFlowOrderService extends JpaSpecificationService<FlowOrderRepository, FlowOrderRepository, FlowOrder, Long> {

    Page<FlowOrder> findAll(Pageable pageable, final Long userId, final Long flowOrderType, final Long orderType, final Short isFinish, final Integer currentStep, final Short isAssign, final String keyword);

    FlowOrder getDetail(Long id);

    List<FlowOrderType> flowOrderTypeList();

    Long getCountDown(FlowOrder flowOrder);

    Long getCountDown(Long orderId);

    Long getCountDownInternal(Long flowOrderId);

    Long getCountDownInternal(FlowOrder flowOrder);

    void saveDialInfo(PhoneCall call);

    void saveMessageInfo(Message message);

    Long saveSignInfo(SignInfo info, int currentStep);

    Long saveSignInfo(SignInfo info, int currentStep, boolean processFlow);

    FeeInfo getMemberFeeInfo(Long flowOrderId);

    boolean isFeeProcess(Long flowOrderId);

    Long saveFeeProcess(Long flowOrderId, Long userId, int currentStep);

    Long saveExecutionRecord(OrderExecutionRecord record, String exceptionData, String diagnoseData, String medicineData, int currentStep, boolean processFlow);

    Long saveExecutionRecord(OrderExecutionRecord record, List<OrderExceptionData> exceptionDataList, List<OrderDiagnose> diagnoseList, List<OrderMedicine> medicineList, int currentStep, boolean processFlow);

    List<PhoneCall> getPhoneCallList(Long flowOrderId, String type);

    List<Message> getMessageList(Long flowOrderId);

    FlowOrder getNextFlowOrder(FlowOrder flowOrder);

    FlowOrder process(Long flowOrderId, Long userId, String logContent, Integer currentStep);

    /**
     * 退号 - 取消订单
     * @param flowOrderId 工单id
     * @param userId 用户id
     * @param cancelReason 退号原因
     */
    void saveCancelOrder(Long flowOrderId, Long userId, String cancelReason);

    /**
     * 退号 - 取消订单
     * @param flowOrderId 工单id
     * @param userId 用户id
     * @param cancelReason 退号原因
     * @param processFlow 是否走流程，从挂号订单中直接退号，无需流程，从中台流转的退号工单需要走流程
     * @return
     */
    Long saveCancelOrder(Long flowOrderId, Long userId, String cancelReason, boolean processFlow);

    /**
     * 中台退号，生成退号工单
     * @param orderId
     * @param userId
     */
    void cancelOrderFromMiddle(Long orderId, Long userId);

    /**
     * 中台改号，生成改号工单
     * @param orderId
     * @param userId
     */
    void reSignOrderFromMiddle(Long orderId, Long userId);

    void saveCancelFlowOrder(Long flowOrderId, Long userId);

    List<UserTask> getAllTask(Long hospitalId);

    List<FlowOrder> getUserTask(Long userId);

    /**
     * 指派工单
     * @param flowOrderId
     * @param userId
     */
    void saveAssignInfo(Long flowOrderId, Long userId);

    /**
     * 获取就诊或体检报告
     * @param flowOrderId
     * @return
     */
    OrderReport getOrderReport(Long flowOrderId);
}
